package com.yunche.yunchebusiness.mvp.presenter

import android.annotation.SuppressLint
import com.yunche.yunchebusiness.base.mvp.BasePresenter
import com.yunche.yunchebusiness.mvp.contract.BrandContract
import com.yunche.yunchebusiness.mvp.model.BrandModel
import com.yunche.yunchebusiness.network.exception.ErrorStatus
import com.yunche.yunchebusiness.network.exception.ExceptionHandle

/**
 * Create by Crcker on 2018/12/21 11:19
 * Email: Crcker@163.com
 */

@SuppressLint("CheckResult")

class BrandPresenter : BasePresenter<BrandContract.View>(), BrandContract.Presenter {

    private val model: BrandModel by lazy {
        BrandModel()
    }

    override fun getBrand() {
        checkViewAttached()
        mRootView?.showLoading()
       var disposable = model.getBrand().subscribe({
            mRootView!!.apply {
                hideLoading()
                if (it.resultCode == ErrorStatus.SUCCESS) {
                    getBrandSuccess(it.datas!!)
                } else {
                    showError(it.message!!)
                }
            }
        }, {
            mRootView?.hideLoading()
            mRootView?.showError(ExceptionHandle.handleException(it))
        })

        addSubscription(disposable)
    }
}